/*
 * RF_recieve.c
 *
 * Created: 4/10/2013 12:58:38 PM
 *  Author: Parag
 */ 


#include <avr/io.h>
#include <avr/delay.h>
#include "U0_UART.h"

#ifndef	F_CPU
#define F_CPU 8000000
#endif


extern FILE uart_stream;


int main(void)
{


stderr = stdout = stdin = &uart_stream;	
int i;	// for counter
char goods[5],data;
DDRB |= (1<<PB1); // Pb1 is output


UARTInit();
UBRRL = 207;				//baudrate 2400
_delay_ms(100);				// safe, need atleast 3 ms to start reciever

    while(1)
    {
		
	
       goods[0] = UARTrecieveRF();
	   if(goods[0] != 'U')	continue;
	   goods[1] = UARTrecieveRF();
	   if(goods[1] != 'U')	continue;
	   
	   for(i = 2;i<5;i++)
	   {
		   goods[i] = UARTrecieveRF();
	   }
	   
	   if(goods[2] != (~goods[3])	continue;
	   if(goods[4] != 'Z' )	continue;
	   
	   data = goods[2];
	   
	   if(data == 'P')
	   {
		   PORTB ^= (1<<PB1);		//Toggles
	   }
	   
	    
    }
}